<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t("指标进度监控") }}</span>
    </div>
    <!-- <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('年月')" prop="days">
        <DatePicker v-model="daysTime" type="monthrange" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form> -->
    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['deal:monthlyMonitoring:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
    </el-row> -->

    <el-table
      v-loading="loading"
      :data="IndexMonitorList"
      border
      tooltip-effect="darkTable"
    >
      <template slot="empty">
        <el-empty description="由于没有实际执行暂无法计算" />
        <!-- <router-link
          target="_self"
          :to="{
            path: '/company/base/companyBaseHome',
            query: { dealId: queryParams.dealId },
          }"
          class="link_a"
        >查看指标监控</router-link> -->
      </template>

      <el-table-column
        :label="$t('序号')"
        type="index"
        align="center"
        show-overflow-tooltip
        width="50"
      >
        <template slot-scope="scope">
          {{
            (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1
          }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('指标名称')" align="center" prop="name" />
      <el-table-column
        :label="$t('投前版本(亿)')"
        align="center"
        prop="beforeValue"
      >
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.beforeValue) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('实际执行') + $t('金额单位')"
        align="center"
        prop="newValue"
      >
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.newValue, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('进度')"
        align="center"
        prop="percent"
      >
        <template slot-scope="scope">
          <el-progress type="circle" :percentage="scope.row.percent" />
        </template>
      </el-table-column>
      <!-- <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['deal:monthlyMonitoring:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-hasPermi="['deal:monthlyMonitoring:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getIndexMonitor } from '@/api/deal/estate/index/dealIndex'
export default {
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 月度监控表格数据
          IndexMonitorList: [],
          // 年月日期范围
          daysTime: [],
          // 弹出层标题
          title: '月度信息',
          // 是否显示弹出层
          formOpen: false,
          // 查询参数
          queryParams: {
            dealId: this.$route.query.id,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {
          },
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getList()
  },
  methods: {
    /** 查询月度监控列表 */
    getList() {
        this.loading = true
        getIndexMonitor(this.queryParams.dealId).then(response => {
           const keys = [
             '土地成本(亿元)',
               '土地成本调整项(亿元)',
                 '除地价外直接投资(亿元)',
                   '总成本(亿元)',
                     '总货值(亿元)'
           ]
           const values = [
             'acreageCost',
               'acreageAdjust',
                 'directInvestment',
                   'totalCost',
                     'totalValue'
           ]
            const arrs = response.rows
            if (arrs.length < 2) {
               this.IndexMonitorList = []
               this.loading = false
               return false
            }
            const beforeValue = new Map(Object.entries(arrs[0]))
              const newValue = new Map(Object.entries(arrs[1]))
                const percent = new Map(Object.entries(arrs[2]))
                const list = []
              for (var i = 0; i < keys.length; i++) {
                const obj = {
                     'name': keys[i],
                     'beforeValue': beforeValue.get(values[i]),
                     'newValue': newValue.get(values[i]),
                     'percent': (percent.get(values[i]) / 10000).toFixed(6)
                }
                list.push(obj)
              }
            this.IndexMonitorList = list
            this.loading = false
        })
    },
    // 表单重置
    reset() {
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    }
  }
}
</script>
